﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace StoryMaker.Application
{
    public class BoolToOppositeBoolConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(bool))
            {
                return !(bool)value;
            }
            else if (targetType == typeof(bool?))
            {
                //assume null is the same as false
                return value == null ? true : !((bool?)value).Value;
            }
            throw new InvalidOperationException("The target must be a bool or bool?");
        }

        public object ConvertBack(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            return Convert(value, targetType, parameter, culture);
        }

        #endregion
    }
}
